package com.android.dfsc;

import com.android.dfsc.data.AC485;
import com.android.dfsc.data.Hris1000System;
import com.android.dfsc.data.HrisCommObject;
import com.android.dfsc.data.HrisDeviceInfo;
import com.android.dfsc.data.HrisFastScenarioInfo;
import com.android.dfsc.data.HrisIrdev;
import com.android.dfsc.data.HrisIrdevMode;
import com.android.dfsc.data.HrisScenarioInfo;
import com.android.dfsc.data.UFH;
import com.android.dfsc.data.Zone;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.wifi.WifiManager;
import android.util.Log;



public class SmartHomeEngine {
	public static int baseTempSet=16;
	private static SmartHomeEngine myInstance=null;
	private String wifiMacAddress=null;
	private String authCode=null;
	private Context context = null;
	private SmartHomeEngine() {
		// TODO Auto-generated constructor stub
		
	}
	
	public static SmartHomeEngine getInstance(){
		if (myInstance==null)
			myInstance=new SmartHomeEngine();
		return myInstance;
	}
	
	static {
		System.loadLibrary("honey");
		myInstance = new SmartHomeEngine();
		
	}
	
	
	public native int initEngine();
	public native int syncData();
	public native void destoryEngine();
	


	public native int sendCmdLight(int id, int action, int onoff, int dimmer);
	public native int sendCmdAc485Cfg(int id, int onoff, int mode, int fan, int dir, int temp);
	public native AC485 sendCmdAc485Req(int id);
	public native int sendCmdIrac(int id, int irid);
	public native int sendCmdIrdev(int id, int irid);
	public native int sendCmdUfhCfg(int id, int onoff, int tempSet);
	public native UFH sendCmdUfhReq(int id);
	public native int sendCmdRelayCfg(int id, int onoff);
	public native int sendCmdRelayReq(int id);
	public native int sendCmdCurtain(int id, int action, int onoff);
	public native int sendCmdZoneCfg(int zoneid, int ztype, int action);
	public native Zone sendCmdZoneReq(int zoneid, int ztype, int statuskey);
	public native int sendCmdScenarioCfg(int sid);
	                  
	public native int sendCmdScenarioReq(int areaid);
	
	public native Hris1000System getAppData();
	public native HrisCommObject[] getAreaData();
	public native HrisCommObject[] getZoneData();
	
	public native HrisCommObject[] getWirelessZoneData();
	public native HrisScenarioInfo[]	getScenarioData();
	public native HrisFastScenarioInfo[] getFastScenarioData();
	

	public native HrisCommObject[] getLightData();
	public native HrisCommObject[] getAc485Data();
	public native HrisIrdev[]	getIracData();
	public native HrisIrdevMode[]	getIracModeData( int i);
	public native HrisCommObject[] getCurtainData();
	public native HrisCommObject[] getUFHData();
	public native HrisCommObject[] getRelayData();
	
	public native HrisIrdev[]	getIrdevData();
	public native HrisIrdevMode[]	getIrdevModeData( int i);
	public native String getAuthCode(GSmartHome app);
	
	public native void syncConfig(String ip,String userName,String password,String UDID,String authCode);

	public String getWifiMacAddress() {
		return wifiMacAddress;
	}

	public void setWifiMacAddress(String wifiMacAddress) {
		this.wifiMacAddress = wifiMacAddress;
	}

	public String getAuthCode() {
		return authCode;
	}

	public void setAuthCode(String authCode) {
		this.authCode = authCode;
	}
	
	public void setConfig(){
		//set config info to c program
		SharedPreferences   clientConfig = context.getSharedPreferences("client_config",0);
		//syncConfig("1","2","3","4","5");
		syncConfig(clientConfig.getString("IP",""),
				clientConfig.getString("user_name",""),
				clientConfig.getString("password",""),
				getAuthCode(),
				clientConfig.getString("auth_code",""));
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}
	
}
